package cn.smile.business.basic.impl;

import cn.smile.bean.dto.basic.MyShopDTO;
import cn.smile.bean.entity.basic.SwiperShop;
import cn.smile.business.basic.IMyShopService;
import cn.smile.business.basic.ISwiperShopService;
import cn.smile.commons.constant.CommonConstant;
import cn.smile.commons.domain.BaseServiceImpl;
import cn.smile.repository.basic.SwiperShopMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import jakarta.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class SwiperShopServiceImpl extends BaseServiceImpl<SwiperShopMapper, SwiperShop> implements ISwiperShopService {

    @Resource
    private IMyShopService shopService;

    @Override
    public List<String> getSwiperUrlList() {
        log.info("[SwiperShopServiceImpl].[getSwiperUrlList] ------> 查询店铺轮播图 URL 列表 Start");
        MyShopDTO shop = shopService.getMyShop();
        List<SwiperShop> baseList = baseMapper.selectList(new QueryWrapper<SwiperShop>().lambda().eq(SwiperShop::getDeleted, Boolean.FALSE).eq(SwiperShop::getShopId, shop.getId()));
        if (CollectionUtils.isEmpty(baseList)) {
            baseList = baseMapper.selectList(new QueryWrapper<SwiperShop>().lambda().eq(SwiperShop::getDeleted, Boolean.FALSE).eq(SwiperShop::getShopId, CommonConstant.DEFAULT_SWIPER_ID));
        }
        List<String> urlList = Lists.newArrayList();
        for (SwiperShop entity : baseList) {
            urlList.add(entity.getUrl());
        }
        log.info("[SwiperShopServiceImpl].[getSwiperUrlList] ------> 查询店铺轮播图 URL 列表 End");
        return urlList;
    }
}
